/**
 * +----------------------------------------------------------------------
 * | InitAdmin/vue-admin [ InitAdmin渐进式模块化通用后台 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2018-2019 http://initadmin.net All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 * +----------------------------------------------------------------------
 * | Author: jry <ijry@qq.com>
 * +----------------------------------------------------------------------
*/
 import apilist from './apibackstage'
let util = {};
// request

util.request = function ({
	method,
    url,
    data,
    success,
    fail,
    complete
}) {
    var header = {
     'ContentType': 'application/x-www-form-urlencoded',
     'X-Requested-With': 'XMLHttpRequest',
    }
	    const token = uni.getStorageSync('refresh_token');
	      if (token) {
			header.Authorization = token;
	      }
	return new Promise((resolve, reject) => {
		 uni.request({
			url: apilist.url+url,
			method: method,
			data: data,
			header: header,
			dataType: 'json',
			success: success,
			fail: (res) => {
				let ret = new Object();
				ret.code = 0;
				ret.msg = '接口或网络异常';
				reject(ret);
			},
			complete: (res) => {
				if (res.statusCode === 200) { //成功
					resolve(res)
				}else{ //失败
					// let ret = new Object()
					// ret.code = res.statusCode
					// ret.msg = res.data.errors
					reject(res)
				}
			}
		})
	});
};

export default util;
